package com.cn.springcloudwechat.common.weiXinPay.sortUntil;

import org.apache.commons.beanutils.PropertyUtilsBean;

import java.beans.PropertyDescriptor;
import java.util.*;


public class SortUtil {
	/**
	 * 字典排序
	 * 
	 * @方法名:sortList
	 * @描述:
	 * @param list
	 * @return
	 */
	public static List sortList(List list) {
		Collections.sort(list);
		return list;
	}

	public static String[] sortString(String[] str) {
		Arrays.sort(str);
		return str;
	}

	// 将javabean实体类转为map类型，然后返回一个map类型的值
	public static SortedMap<Object,Object> beanToMap(Object obj) {
		SortedMap<Object,Object> parameters = new TreeMap<Object,Object>();
		try {
			PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
			PropertyDescriptor[] descriptors = propertyUtilsBean.getPropertyDescriptors(obj);
			for (int i = 1; i < descriptors.length; i++) {
				String name = descriptors[i].getName();
				if (!"class".equals(name)) {
					parameters.put(name, propertyUtilsBean.getNestedProperty(obj, name));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return parameters;
	}

	public static void main(String[] args) {
		
	}
}
